package com.example.address_list.slice;

import com.example.address_list.DataAbility;
import com.example.address_list.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.DataAbilityHelper;
import ohos.aafwk.ability.DataAbilityRemoteException;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.data.dataability.DataAbilityPredicates;
import ohos.data.resultset.ResultSet;
import ohos.utils.net.Uri;

public class main_seeSlice extends AbilitySlice {
    Text text;
    DataAbilityHelper dataAbilityHelper;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main_see);
        text= (Text) findComponentById(ResourceTable.Id_text_id);
        dataAbilityHelper=DataAbilityHelper.creator(this);
        Uri uri=Uri.parse("dataability:///com.example.address_list.DataAbility/student");
        String[]colums={"id","name","age"};
        DataAbilityPredicates dataAbilityPredicates=new DataAbilityPredicates();
        try {
           ResultSet resultSet=dataAbilityHelper.query(uri,colums,dataAbilityPredicates);
            int count=resultSet.getRowCount();
            if (count>0){
                resultSet.goToFirstRow();
                do {
                    int userid=resultSet.getInt(0);
                    String username=resultSet.getString(1);
                    int userage=resultSet.getInt(2);
                    text.setText(userid+"   "+username+"   "+userage);
                }while (resultSet.goToNextRow());
            }
        } catch (DataAbilityRemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
